package com.example.config;

import com.example.bean.Chick;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportRegister implements ImportBeanDefinitionRegistrar {
    /**
     * 自定义手动注册bean
     * @param metadata 当前类注解信息
     * @param registry beanDefinition注册类
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {

        if ( !registry.containsBeanDefinition("chick") ) {
            BeanDefinition definition = new RootBeanDefinition(Chick.class);
            registry.registerBeanDefinition("chick", definition);
        }

    }
}




